package com.cwnu.sw.cys.core.websocket.service.adapter;

import com.cwnu.sw.cys.core.user.domain.entity.User;
import com.cwnu.sw.cys.core.websocket.domain.enums.WSRespTypeEnum;
import com.cwnu.sw.cys.core.websocket.domain.vo.resp.WSBaseResp;
import com.cwnu.sw.cys.core.websocket.domain.vo.resp.WSBlack;
import com.cwnu.sw.cys.core.websocket.domain.vo.resp.WSLoginSuccess;
import com.cwnu.sw.cys.core.websocket.domain.vo.resp.WSLoginUrl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;

/**
 * @author jisam
 * @version 1.0
 * @contact "jisamchan@outlook.com"
 * @date 13/02/2025
 * @description 处理发送到前端的文本
 */
public class WebSocketBuilder {


    public static WSBaseResp<?> build(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WSBaseResp<WSLoginUrl> resp = new WSBaseResp<>();
        String url = wxMpQrCodeTicket.getUrl();
        System.out.println("\n" + url + "\n" );
        resp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        resp.setData(new WSLoginUrl(url));
        return resp;
    }


    public static WSBaseResp<WSLoginSuccess> buildResp(User user, String token,boolean hasPower)
    {
        WSBaseResp<WSLoginSuccess> resp = new WSBaseResp<>();
        Integer type = WSRespTypeEnum.LOGIN_SUCCESS.getType();
        System.out.println(type);
        resp.setType(type);

        WSLoginSuccess wsLoginSuccess = WSLoginSuccess.builder()
                .uid(user.getId())
                .token(token)
                .name(user.getName())
                .avatar(user.getAvatar())
                .power(hasPower ? 1 : 0)
                .build();
        System.out.println(wsLoginSuccess);
        resp.setData(wsLoginSuccess);
        return resp;
    }

    public static WSBaseResp<WSLoginSuccess> buildInvalidTokenResp() {
        WSBaseResp<WSLoginSuccess> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.INVALIDATE_TOKEN.getType());
        return wsBaseResp;
    }

    public static WSBaseResp<?> buildScanSuccessResp() {
        WSBaseResp wsBaseResp = new WSBaseResp();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_SCAN_SUCCESS.getType());
        return wsBaseResp;
    }

    public static WSBaseResp<?> buildBlack(User user) {
        WSBaseResp<WSBlack> resp = new WSBaseResp<>();
        WSBlack black = new WSBlack(user.getId());
        resp.setData(black);
        resp.setType(WSRespTypeEnum.BLACK.getType());
        return resp;
    }
}
